﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Engine
{
    public class TextParser
    {
        public static IEnumerable<Class> FindClasses(String[] lines)
        {
            List<Class> Types = new List<Class>();

            for (Int32 i = 0; i < lines.Length; i++)
            {
                if (!String.IsNullOrEmpty(lines[i]))
                {
                    if (lines[i].Contains("class"))
                    {
                        if (!lines[i].Contains("abstract"))
                        {
                            String name = lines[i].Trim();

                            if (name.Contains(":"))
                            {
                                // remove inheritance and interfaces
                                name = name.Split(':')[0].Trim();
                            }

                            if (name.StartsWith("public") || name.StartsWith("private") || name.StartsWith("internal"))
                            {
                                name = name.Split(' ')[2]; //assume naming convention access modifer then class name
                            }
                            else
                            {
                                name = name.Split(' ')[1];
                            }

                            Types.Add(new Class() { Name = name });
                        }
                    }
                }
            }

            return Types;
        }
    }
}
